// 云函数 index.js
const cloud = require('wx-server-sdk')
cloud.init()
const got = require('got'); // 使用 got 请求库
const cheerio = require('cheerio'); // HTML 解析

exports.main = async (event, context) => {
  const res = await got('https://news.10jqka.com.cn/hotnews_list/');
  const $ = cheerio.load(res.body);

  const headlines = [];

  $('a').each((i, elem) => {
    const href = $(elem).attr('href');
    const title = $(elem).text();
    if (href && title && href.includes('/202') && title.length > 8) {
      headlines.push({ title, url: href });
    }
    if (headlines.length >= 5) return false;
  });

  return { headlines };
}
